package com.swm.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@XmlAccessorType(XmlAccessType.FIELD)
//@XmlType(name = "", propOrder = { "id", "password" })
@XmlRootElement(name = "User")
@PersistenceCapable
public class User {
	
	public User() {
	}
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	public static Key generateKey(String name) {
		return KeyFactory.createKey( User.class.getSimpleName(), name );
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}
	
	@Persistent
	private String id;
	
	@Persistent
	private String password;

	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public boolean isEqual( User user ){
		if( id.equals( user.getId()) && password.equals( user.getPassword() ))
			return true;
		return false;
	}
	
	public boolean isEqual( String userID ){
		if( id.equals( userID ))
			return true;
		return false;
	}
}
